// Decompiled by Jad v1.5.7f. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   MemoAction.java

package com.iphaeton.lms.action.memo;

import com.iphaeton.common.helper.UserSession;
import com.iphaeton.exception.BusinessException;
import com.iphaeton.lms.business.memo.IMemoService;
import com.iphaeton.lms.pojo.memo.Memo;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.apache.log4j.Logger;
import org.apache.struts.action.*;

// Referenced classes of package com.iphaeton.lms.action.memo:
//            MemoBizSupportAction

public class MemoAction extends MemoBizSupportAction
{

    public MemoAction()
    {
    }

    public ActionForward addMemo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        daf = (DynaActionForm)form;
        String name = request.getParameter("name");
        String content = (String)daf.get("content");
        String date = (String)daf.get("date");
        java.util.List list;
        try
        {
            String user_id = ((UserSession)request.getSession().getAttribute("userSession")).getId();
            Memo m = new Memo();
            m.setName(name);
            m.setContent(content);
            m.setUserId(user_id);
            m.setDate(date);
            m = memo.save(m);
            list = memo.findMemo(user_id, date);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        request.setAttribute("date", date);
        request.setAttribute("list", list);
        return mapping.findForward("memo_list");
    }

    public ActionForward findMemo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String user_id = ((UserSession)request.getSession().getAttribute("userSession")).getId();
        String date = request.getParameter("date");
        if(date == null || "".equals(date))
        {
            Calendar cal = Calendar.getInstance();
            java.util.Date time = cal.getTime();
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            date = df.format(time);
        }
        java.util.List list;
        try
        {
            list = memo.findMemo(user_id, date);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("date", date);
        request.setAttribute("list", list);
        return mapping.findForward("memo_list");
    }

    public ActionForward editMemo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String id = request.getParameter("id");
        Memo m;
        try
        {
            m = memo.findMemoById(id);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("memo", m);
        return mapping.findForward("memo_edit");
    }

    public ActionForward removeMemo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String id = request.getParameter("id");
        String date = "";
        java.util.List list;
        try
        {
            Memo m = memo.findMemoById(id);
            date = m.getDate();
            memo.remove(id);
            list = memo.findMemo(m.getUserId(), date);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("date", date.substring(0, 10));
        request.setAttribute("list", list);
        return mapping.findForward("memo_list");
    }

    public ActionForward updateMemo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        String content = request.getParameter("content");
        String date = request.getParameter("date");
        java.util.List list;
        try
        {
            Memo m = memo.findMemoById(id);
            m.setName(name);
            m.setContent(content);
            m.setDate(date);
            memo.save(m);
            list = memo.findMemo(m.getUserId(), date);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        request.setAttribute("date", date);
        request.setAttribute("list", list);
        return mapping.findForward("memo_list");
    }

    public ActionForward todayMemo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
    {
        Calendar cal = Calendar.getInstance();
        java.util.Date time = cal.getTime();
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String date = df.format(time);
        java.util.List list;
        try
        {
            String user_id = ((UserSession)request.getSession().getAttribute("userSession")).getId();
            list = memo.findMemo(user_id, date);
        }
        catch(BusinessException e)
        {
            e.printStackTrace();
            request.setAttribute("exception", e);
            return mapping.findForward("failure");
        }
        catch(NullPointerException ne)
        {
            return mapping.findForward("session_dead");
        }
        request.setAttribute("list", list);
        return mapping.findForward("memo_today");
    }

    private static Logger logger;
    private DynaActionForm daf;
    static Class class$0; /* synthetic field */

    static 
    {
        logger = Logger.getLogger(com.iphaeton.lms.action.memo.MemoAction.class.getName());
    }
}
